﻿using System;
using Blog.Infrastructure.Configuration.Blog.Infrastructure.Config;
using Blog.Infrastructure.DataAcces.Repositories.Abstractisations;
using Blog.Infrastructure.DataAcces.Repositories.Implementaions;
using NHibernate;

namespace Blog.Infrastructure.Tests.RepositoryTests
{
    public class RepositoryTestsBase
    {
        protected static readonly ISessionFactory SessionFactory = NHibernateConfigurator.InMemorySessionFactory();

        protected void PopulateDb(Action<ISession> act)
        {
            var msession = SessionFactory.OpenSession();

            act.Invoke(msession);
        }

        protected ISession NewSession()
        {
            return SessionFactory.OpenSession();
        }

        protected virtual IRepository<T> GetRepositoryOf<T>()
        {
            return new Repository<T>(SessionFactory);
        }
    }
}